package com.xiran.srpingboottemplateself.controller;

import com.xiran.srpingboottemplateself.common.Response;
import com.xiran.srpingboottemplateself.pojo.entity.Blog;
import com.xiran.srpingboottemplateself.pojo.entity.User;
import com.xiran.srpingboottemplateself.pojo.vo.UserVO;
import com.xiran.srpingboottemplateself.service.BlogService;
import com.xiran.srpingboottemplateself.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "管理员模块")
@RestController
@RequestMapping("/api/admin")
@RequiredArgsConstructor
public class AdminController {

    private final UserService userService;
    private final BlogService blogService;

    @ApiOperation("管理员仪表板")
    @GetMapping("/dashboard")
    public Response<String> dashboard() {
        return Response.success("欢迎访问管理员仪表板");
    }

    @ApiOperation("获取所有用户")
    @GetMapping("/users")
    public Response<List<User>> getAllUsers() {
        List<User> users = userService.getAllUsers();
        return Response.success(users);
    }

    @ApiOperation("获取所有博客")
    @GetMapping("/blogs")
    public Response<List<Blog>> getAllBlogs() {
        List<Blog> blogs = blogService.getAllBlogs();
        return Response.success(blogs);
    }

    @ApiOperation("删除用户")
    @DeleteMapping("/users/{id}")
    public Response<String> deleteUser(@PathVariable Long id) {
        boolean success = userService.deleteUser(id);
        return success ? Response.success("用户删除成功") : Response.fail("用户删除失败");
    }

    @ApiOperation("删除博客")
    @DeleteMapping("/blogs/{id}")
    public Response<String> deleteBlog(@PathVariable Long id) {
        boolean success = blogService.deleteBlogByAdmin(id);
        return success ? Response.success("博客删除成功") : Response.fail("博客删除失败");
    }
}